package com.woniuxy.userassembly.apiimpl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.api.UserCredit;
import com.woniuxy.common.PageResult;
import com.woniuxy.common.Result;
import com.woniuxy.form.UserCreditForm;
import com.woniuxy.userassembly.model.RbacRole;
import com.woniuxy.userassembly.model.UserCreditInfo;
import com.woniuxy.userassembly.service.IUserCreditInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Liyfi
 * @since 2021-05-25
 */
@RestController
@Slf4j
public class UserCreditInfoController implements UserCredit {
    @Autowired
    private IUserCreditInfoService service;

    @Override
    public Result addUserCredit(UserCreditForm form) {
        log.info("新增积分变动记录,{}",form);
        UserCreditInfo userCreditInfo = new UserCreditInfo();
        BeanUtils.copyProperties(form,userCreditInfo);
        int i = service.addUserCreditInfo(userCreditInfo);
        if(i == 1){
            return Result.success("新增成功");
        }else {
            return Result.fail("新增失败");
        }
    }

    @Override
    public PageResult findUserCredit(int pageIndex) {
        Page<UserCreditInfo> pageParam = new Page<>(pageIndex,10L);
        IPage<UserCreditInfo> pageResult = service.page(pageParam);
        PageResult<UserCreditInfo> myPageResult = new PageResult<UserCreditInfo>((int) pageResult.getTotal(), (int) pageResult.getCurrent(), (int) pageResult.getSize(), pageResult.getRecords());
        myPageResult.setSuccess(true);
        return myPageResult;
    }
}

